﻿Ext.define('MetaData', {
    extend: 'Ext.data.Model',
    fields: [
        "Id"
	    , "FText"   //功能名称
	    , "FValue"   //权限值
	    , "FOrder"   //序号
        , "IsChecked"
    ],
    idProperty: "Id"
});

Ext.define('SHApp.System.MetaData.Grid1', {
    extend: 'BLBTSystem.grid',
    alias: 'shapp.system.grid',
    requires: ['Ext.ux.CheckColumn'],
    dataModel: "MetaData",
    dataUrl:"api/checkmetadata?format=json",
    firstLoad: false,
    sortInfield: 'FValue', //排序字段
    hasPageBar: false,
    funcID: "",
    isSelModel: false,
    funcGrid: null,
    autoSync: false,
    isAsc: 'asc',     //升序还是降序
    initComponent: function () {
        var me = this;
        Ext.apply(this);
        me.btnAddID += me.id;
        me.btnEditID += me.id;
        me.btnDeleteID += me.id;
        this.creatTbar();
        this.creatColumns();
        this.callParent(arguments);
        this.checkBtnPermission(me.pvalue);
    },
    loadByFuncID: function (funcID) {
        this.funcID = funcID;
        this.down("#" + this.btnSaveID).setDisabled(funcID == "");
        this.down("#" + this.btnResetID).setDisabled(funcID == "");
        var store = this.store;
        store.proxy.url = "api/checkmetadata?format=json&funcID=" + this.funcID;
        store.load();

    },
    creatColumns: function () {
        var me = this;
        me.columns = [
            {
                text: "Id",
                
                dataIndex: 'Id',
                sortable: false,
                hidden: true
            }, {
                text: "功能名称",
                dataIndex: 'FText',
                flex: 1,
                sortable: false
            }, {
                text: "权限值",
                width: 80,
                dataIndex: 'FValue',
                hidden: true,
                sortable: false
            }, {
                xtype: 'checkcolumn',
                text: '操作',
                dataIndex: 'IsChecked',
                width: 40,
                sortable: false
            }, {
                text: "序号",
                width: 100,
                dataIndex: 'FOrder',
                sortable: true,
                hidden: true
            }
		]
    },
    creatTbar: function () {
        var me = this;
        me.tbar = [
		    '->', {
		        xtype: 'button',
		        text: '保存',
		        id: me.btnSaveID,
		        disabled: true,
		        iconCls: 'icon-btn-save',
		        handler: function () {
		            me.store.proxy.url = me.dataUrl + "&funcID=" + me.funcID + "&"
		            me.store.update();
		            me.funcGrid.store.load();
		        }
		    }, {
		        xtype: 'button',
		        disabled: true,
		        id: me.btnResetID,
		        text: '重置',
		        iconCls: 'icon-btn-reset',
		        handler: function () {
		            me.store.load();
		        }
		    }
        ]
    }
})

